#include <stdio.h>
#include <stdlib.h>
#include "member.h"

#define ADMIN_INFO_FILE "admin_info.dat"

void display_menu(void)
{
    printf("\n===== 篮球馆会员管理系统 =====\n");
    printf("1. 会员注册\n");
    printf("2. 查询会员信息\n");
    printf("3. 会员入场/离场\n");
    printf("4. 管理员登录\n");
    printf("5. 修改会员信息（管理员）\n");
    printf("6. 注销会员（管理员）\n");
    printf("0. 退出系统\n");
    printf("请选择操作：");
}



int main()
{
    int choice;
    
    if (!file_exists(ADMIN_INFO_FILE))
    {
        FILE *fp = fopen(ADMIN_INFO_FILE, "wb");
        if (fp)
        {
            admin_info admin;
            strcpy(admin.username, "admin");
            strcpy(admin.password, "admin123");
            fwrite(&admin, sizeof(admin), 1, fp);
            fclose(fp);
            printf("已创建默认管理员账户：用户名-admin，密码-admin123\n");
        }
    }
    
    printf("欢迎使用篮球馆会员管理系统！\n");
    
    while(1)
    {
        display_menu();
        if(scanf("%d", &choice) != 1)
        {
            printf("输入错误，请重新选择！\n");
            while(getchar() != '\n'); // 清空输入缓冲区
            continue;
        }
        
        switch(choice)
        {
            case 1:
                member_reg();
                break;
            case 2:
                member_show();
                break;
            case 3:
                member_access();
                break;
            case 4:
                admin_login();
                break;
            case 5:
                member_modify();
                break;
            case 6:
                member_delete();
                break;
            case 0:
                printf("感谢使用篮球馆会员管理系统！再见！\n");
                return 0;
            default:
                printf("无效选择，请重新输入！\n");
        }
        
        // 清空输入缓冲区，避免影响下一次输入
        while(getchar() != '\n');
    }
    
    return 0;
}